$(document).ready(function() {
	$('#enterprise').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
		"bServerSide" : true, //是否启动服务器端数据导入
		"bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
		"bJQueryUI" : true, //是否使用 jQury的UI theme
		"aLengthMenu" : [5, 10, 15], //更改显示记录数选项
		"iDisplayLength" : 10, //默认显示的记录数
		"bAutoWidth" : true, //是否自适应宽度 update
		"bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
		"bPaginate" : false, //是否显示（应用）分页器
		"bInfo" : false, //是否显示页脚信息，DataTables插件左下角显示记录数
		"sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
		"bSort" : true, //是否启动各个字段的排序功能
		"aaSorting" : [[0, "ASC"]], //默认的排序方式，第3列，升序排列
		"bFilter" : false, //是否启动过滤、搜索功能
		"sPaginationType": "full_numbers",
		"sScrollX": '100%',
		"sScrollXInner": 2000,
		"sAjaxSource":parent.basePath+"sys/LoanRepaymentDetail/list",
		"fnServerData":retrieveData,  //自定义数据获取函数
		"aoColumns" : [ {
			"mDataProp" : "deadlineNumber",
			"sTitle" : "期数",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "repayEndDate",
			"sTitle" : "应还日期",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				if(_is_empty(data)){
					return '';
				}
				return new Date(data).format('yyyy-MM-dd');
			}
		}, {
			"mDataProp" : "repayRealDate",
			"sTitle" : "实还日期",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				if(_is_empty(data)){
					return '';
				}
				return new Date(data).format('yyyy-MM-dd');
			}
		},{
			"mDataProp" : "realCapital/planCapital",
			"sTitle" : "已收/应收本金",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realCapital=row.realCapital,planCapital=row.planCapital;
				return realCapital+'/'+planCapital;
			}
		},{
			"mDataProp" : "realInterest/planInterest",
			"sTitle" : "已收/应收利息",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realInterest=row.realInterest,planInterest=row.planInterest;
				return realInterest+'/'+planInterest;
			}
		}, {
			"mDataProp" : "realInspectFee/planInspectFee",
			"sTitle" : "已收/应收调查费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realInspectFee=row.realInspectFee,planInspectFee=row.planInspectFee;
				return realInspectFee+'/'+planInspectFee;
			}
		}, {
			"mDataProp" : "realHandingFee/planHandingFee",
			"sTitle" : "已收/应收手续费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realHandingFee=row.realHandingFee,planHandingFee=row.planHandingFee;
				return realHandingFee+'/'+planHandingFee;
			}
		}, {
			"mDataProp" : "realManageFee/planManageFee/reduceManageFee",
			"sTitle" : "已收/应收/减免管理费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realManageFee=row.realManageFee,planManageFee=row.planManageFee,reduceManageFee=row.reduceManageFee;
				return realManageFee+'/'+planManageFee+'/'+reduceManageFee;
			}
		}, {
			"mDataProp" : "realOverdueFee/planOverdueFee/reduceOverdueFee",
			"sTitle" : "已收/应收/减免滞纳金",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realOverdueFee=row.realOverdueFee,planOverdueFee=row.planOverdueFee,reduceOverdueFee=row.reduceOverdueFee;
				return realOverdueFee+'/'+planOverdueFee+'/'+reduceOverdueFee;
			}
		},
		{
			"mDataProp" : "realBreachFee/planBreachFee/reduceBreachFee",
			"sTitle" : "已收/应收/减免违约金",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realBreachFee=row.realBreachFee,planBreachFee=row.planBreachFee,reduceBreachFee=row.reduceBreachFee;
				return realBreachFee+'/'+planBreachFee+'/'+reduceBreachFee;
			}
		},
		{
			"mDataProp" : "realCollectionFee/planCollectionFee/reduceCollectionFee",
			"sTitle" : "已收/应收/减免催收费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realCollectionFee=row.realCollectionFee,planCollectionFee=row.planCollectionFee,reduceCollectionFee=row.reduceCollectionFee;
				return realCollectionFee+'/'+planCollectionFee+'/'+reduceCollectionFee;
			}
		},
		{
			"mDataProp" : "realLegalFee/planLegalFee/reduceLegalFee",
			"sTitle" : "已收/应收/减免法诉费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realLegalFee=row.realLegalFee,planLegalFee=row.planLegalFee,reduceLegalFee=row.reduceLegalFee;
				return realLegalFee+'/'+planLegalFee+'/'+reduceLegalFee;
			}
		},
		{
			"mDataProp" : "realTotal/planTotal/reduceTotal",
			"sTitle" : "已收/应收/减免总额",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var realTotal=row.realTotal,planTotal=row.planTotal,reduceTotal=row.reduceTotal;
				return realTotal+'/'+planTotal+'/'+reduceTotal;
			}
		},{
			"mDataProp" : "repayStatus",
			"sTitle" : "还款状态",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {	
				var returnStr = top.SYS_BASE_DATA['Loan_Repayment_Status_Code'][data];
				return returnStr;
			}
		},{
			"mDataProp" : "overdueStatus",
			"sTitle" : "逾期状态",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {	
				var returnStr = top.SYS_BASE_DATA['Loan_Overdue_Status_Code'][data];
				return returnStr;
			}
		},{
			"mDataProp" : "repayType",
			"sTitle" : "结算方式",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {	
				var returnStr = top.SYS_BASE_DATA['Loan_Close_Account_Mode_Code'][data];
				return returnStr;
			}
		}
		/*
		,
		{
			"mDataProp" : "uid",
			"sTitle" : "操作",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var id=row.id,loanId=row.loanId,repaymentId=row.repaymentId,repayStatus=row.repayStatus,receivablesStatus=row.receivablesStatus;
				return parent._set_href(repayStatus,[id,loanId],{
					1:[{'title':'收款','func':'receivables'}],
					2:[{'title':'查看','func':'query'}]
			});
				// return '<a href="javascript:void(0)" onclick="queryDetail('+id+','+loanId+')" class="tablelink">收款明细</a>';
			}
		}*/
		],
		"oLanguage": {
			"sUrl":parent.basePath+"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
		}
	});
	
	var url = 'sys/LoanExt/findRepayment?queryProxy[id]='+repaymentId;
	_set_default_lable_text(url,true);

});


var receivables = function(id,loanId,repaymentId){
	parent._do_goto_right('jsp/loan/loan_repayment_detail_edit.jsp?id='+id+'&loanId='+loanId+'&repaymentId='+repaymentId);
};
var query = function(id,loanId,repaymentId){
	parent._do_goto_right(parent.basePath+'jsp/loan/loan_repayment_detail.jsp?id='+id+'&loanId='+loanId+'&repaymentId='+repaymentId);
};

//自定义数据获取函数
function retrieveData( sSource, aoData, fnCallback ) {
	aoData.push({name:'beanProxy[enable]',value:0});
	aoData.push({name:'beanProxy[loanId]',value:loanId});
	aoData.push({name:'beanProxy[repaymentId]',value:repaymentId});
	aoData.push({name:'isNonPage',value:1});
	aoData.push({name:"v2hldghlcib0agugzgf0ysbhy2nlc3m",value:1});
	$.ajax( {
		type: "POST", 
		url: sSource, 
		cache : false,
		dataType : "json",
		data : aoData, 
		success: function(resp) {
			if(resp && resp.state == 200){
				fnCallback(resp.datagrid);
				return false;
			}
			fnCallback(null);
		}
	});
}
